<template>
    <div style="width: 800px;">
        <div class="center mtb30">
            <div style="width: 800px;">
                <el-form :model="data" label-width="180px">
                    <el-form-item label="企业合同模板地址">
                        <el-input v-model="data.contractTemplatePath" placeholder="请输入企业合同模板地址" :disabled="disabled" />
                    </el-form-item>
                    <el-form-item label="企业合同模板预览地址">
                        <el-input v-model="data.contractTemplateUrl" placeholder="请输入企业合同模板预览地址" :disabled="disabled" />
                    </el-form-item>
                </el-form>

            </div>
        </div>
         <div v-if="permissionStore.isPermissionsBtn('001008002')">
             <div class='centerV' v-if="disabled">
            <el-button type="primary" :icon="Edit" @click="disabled = false">修改</el-button>
        </div>
        <div class='justify-center align-center' v-else>
            <el-button @click="onCancel">取 消</el-button>
            <el-button type="primary" @click="onSubmit" :loading="loading">确 定</el-button>
        </div>
         </div>
       
    </div>
</template>

<script setup lang="ts">
import { Edit } from '@element-plus/icons-vue'
import { systemConfigListApi, editSystemConfigApi } from '@/api/auth/operationConfiguration'
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import {usePermissionStore} from '@/store/modules/permission'
 const permissionStore = usePermissionStore()
const openDialog = async () => {
    if (disabled.value == false) return
    let res: any = await systemConfigListApi({ id: 'FILE_PATH_CONFIG' })
    if (res.code == 200) {
        data.value = res.data
        rowData.value = res.data
    }
}

const data = ref({
    contractTemplatePath: '',
    contractTemplateUrl: ''
})
const rowData = ref({
    contractTemplatePath: '',
    contractTemplateUrl: ''
})

const disabled = ref(true)

const onCancel = () => {
    data.value = rowData.value
    disabled.value = true
}

const loading = ref(false)
const onSubmit = () => {
    loading.value = true;
    let obj = {
        "type": "FILE_PATH_CONFIG",
        "value": data.value
    }
    //添加
    editSystemConfigApi(obj)
        .then(() => {
            ElMessage.success('配置成功');
            disabled.value = true
        })
        .finally(() => {
            loading.value = false;
        });
}


// 导出方法
defineExpose({
    openDialog
});

</script>

<style scoped></style>